﻿/*----------------------------------------------------------------
// Copyright (C) 2015 HYBY
//
// 文件名：        TAModular.cs
// 文件功能描述：   基础表，模块设定表
//
// 
// 创建标识：      吕天瑞 2016-06-07
//
// 修改标识：
// 修改描述： 
// 
// 备注：	
// 				
//----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using HYBY.Task.DataEntity;
using HYBY.Task.Repository.IRepository;

namespace HYBY.Task.Repository 
{
    public partial class TAModularRepository : BaseRepository<TAModularEntity>, ITAModularRepository 
    {

        #region 常量    

        private const String CONST_GetTAModular = "TaskPlatformDB#GetTAModular";
        private const String CONST_GetTAModulars = "TaskPlatformDB#GetTAModulars";
        private const String CONST_GetTAModularPaged = "TaskPlatformDB#GetTAModularPaged";
        private const String CONST_GetTAModularRecordCount = "TaskPlatformDB#GetTAModularRecordCount";
        private const String CONST_SaveTAModular = "TaskPlatformDB#SaveTAModular";
        private const String CONST_DeleteTAModular = "TaskPlatformDB#DeleteTAModular";
        private const string CONST_GetTAModularByWhere = "TaskPlatformDB#GetTAModularByWhere";

        #endregion

        #region 构造器

        public TAModularRepository() {

        }

        #endregion

        #region 公共方法

        /// <summary>
        /// 返回基础表，模块设定表
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public override TAModularEntity Get(object Id) 
        {
            return Query<TAModularEntity>(CONST_GetTAModular, new { ID = Id }).ToList().FirstOrDefault();
        }

        /// <summary>
        /// 返回所有基础表，模块设定表
        /// </summary>
        /// <returns></returns>
        public List<TAModularEntity> GetTAModulars()
        {
            return Query<TAModularEntity>(CONST_GetTAModulars).ToList();
        }


        /// <summary>
        /// 分页方式返回基础表，模块设定表
        /// </summary>
        /// <param name="PageIndex">页面索引</param>
        /// <param name="PageSize">页面大小</param>
        /// <param name="RecordCount">总记录数</param>
        /// <returns></returns>
        public List<TAModularEntity> GetTAModulars(int pageIndex,int pageSize,out int recordCount)
        {
            recordCount = Query<Int32>(CONST_GetTAModularRecordCount).FirstOrDefault();
            return Query<TAModularEntity>(CONST_GetTAModularPaged, new { PageIndex = pageIndex,PageSize=pageSize }).ToList();
        }

        /// <summary>
        /// 保存领域实体到持久化存储基础表，模块设定表
        /// </summary>
        /// <param name="entity">领域实体</param>    
        /// <returns></returns>
        public override bool Save(TAModularEntity entity) 
        {
            return Execute(CONST_SaveTAModular, entity) > 0;
        }

        /// <summary>
        /// 从持久化存储中删除基础表，模块设定表
        /// </summary>
        /// <param name="entity">领域实体</param>    
        /// <returns></returns>
        public override bool Delete(TAModularEntity entity) 
        {
            return Execute(CONST_DeleteTAModular, new {  Id = entity.ID }) > 0;
        }

        #endregion
        #region 扩展方法

        public List<TAModularEntity> GetTAModularByWhere(TAModularEntity entity)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();

            dic.Add("FatherId", entity.FatherId);
            dic.Add("ProductId", entity.ProductId);
            dic.Add("ModularTypeId", entity.ModularTypeId); 

            return Query<TAModularEntity>(CONST_GetTAModularByWhere, entity).ToList();
        }

        #endregion
    }  
}

